package cn.elane.elastic.core.service.controller;

import cn.elane.elastic.core.service.biz.ServiceBiz;
import cn.elane.elastic.global.model.NameBean;
import cn.elane.elastic.global.render.R;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

@Api(value = "Service", tags = {"服务/接口/图层/其它."})
@RequestMapping("/")
@RestController
public class Service {

	@Resource
	private ServiceBiz biz;

	@ApiOperation(value = "环境列表", notes = "环境列表.")
	@ApiImplicitParams({
			@ApiImplicitParam(name = "start", value = "开始时间.", paramType = "query", dataType = "String", required = true),
			@ApiImplicitParam(name = "end", value = "结束时间.", paramType = "query", dataType = "String", required = true),
	})
	@GetMapping("service/getEnvironment")
	public R getEnvironment(String start, String end) {
		return biz.getEnv(start, end);
	}

	@ApiOperation(value = "服务名称列表", notes = "服务名称列表.")
	@GetMapping("getServiceNames")
	public R getServiceNames() {
		return biz.getServiceNames();
	}

	@ApiOperation(value = "服务-主机名/探针条件", notes = "服务-主机名/探针条件.")
	@ApiImplicitParams({
			@ApiImplicitParam(name = "start", value = "开始时间.", paramType = "query", dataType = "String", required = true),
			@ApiImplicitParam(name = "end", value = "结束时间.", paramType = "query", dataType = "String", required = true),
			@ApiImplicitParam(name = "environment", value = "环境.", paramType = "query", dataType = "String", required = false),
	})
	@GetMapping("service/getParams")
	public R getParams(String start, String end, String environment) {
		return biz.getParams(start, end, environment);
	}

	@ApiOperation(value = "服务列表", notes = "服务列表.")
	@ApiImplicitParams({
			@ApiImplicitParam(name = "param", value = "JSON对象.", paramType = "body", dataType = "Map", required = true),
			@ApiImplicitParam(name = "示例参数：start", value = "开始时间.", dataType = "String", required = false),
			@ApiImplicitParam(name = "示例参数：end", value = "结束时间.", dataType = "String", required = false),
			@ApiImplicitParam(name = "示例参数：environment", value = "环境.", dataType = "String", required = false),
			@ApiImplicitParam(name = "示例参数：host", value = "主机.", dataType = "String", required = false),
			@ApiImplicitParam(name = "示例参数：agentName", value = "探针.", dataType = "String", required = false),
			@ApiImplicitParam(name = "示例参数：serviceName", value = "应用名称/服务名称.", dataType = "String", required = false),
	})
	@PostMapping("service/list")
	public R list(@RequestBody NameBean param) {
		return biz.list(param);
	}

	@ApiOperation(value = "接口-主机名/探针/交易结果条件", notes = "接口-主机名/探针/交易结果条件.")
	@ApiImplicitParams({
			@ApiImplicitParam(name = "start", value = "开始时间.", paramType = "query", dataType = "String", required = true),
			@ApiImplicitParam(name = "end", value = "结束时间.", paramType = "query", dataType = "String", required = true),
			@ApiImplicitParam(name = "environment", value = "环境.", paramType = "query", dataType = "String", required = false),
	})
	@GetMapping("trace/getParams")
	public R getTraceParams(String start, String end, String environment) {
		return biz.getTraceParams(start, end, environment);
	}

	@ApiOperation(value = "接口列表(基础)", notes = "接口列表.")
	@ApiImplicitParams({
			@ApiImplicitParam(name = "param", value = "JSON对象.", paramType = "body", dataType = "Map", required = true),
			@ApiImplicitParam(name = "示例参数：start", value = "开始时间.", dataType = "String", required = false),
			@ApiImplicitParam(name = "示例参数：end", value = "结束时间.", dataType = "String", required = false),
			@ApiImplicitParam(name = "示例参数：environment", value = "环境.", dataType = "String", required = false),
			@ApiImplicitParam(name = "示例参数：host", value = "主机.", dataType = "String", required = false),
			@ApiImplicitParam(name = "示例参数：result", value = "交易结果.", dataType = "String", required = false),
			@ApiImplicitParam(name = "示例参数：serviceName", value = "应用名称/服务名称.", dataType = "String", required = false),
	})
	@PostMapping("trace/list")
	public R traceList(@RequestBody NameBean param) {
		return biz.traceList(param);
	}

	@ApiOperation(value = "接口详情", notes = "接口详情.")
	@ApiImplicitParams({
			@ApiImplicitParam(name = "param", value = "JSON对象.", paramType = "body", dataType = "Map", required = true),
			@ApiImplicitParam(name = "示例参数：start", value = "开始时间.", dataType = "String", required = false),
			@ApiImplicitParam(name = "示例参数：end", value = "结束时间.", dataType = "String", required = false),
			@ApiImplicitParam(name = "示例参数：environment", value = "环境.", dataType = "String", required = false),
			@ApiImplicitParam(name = "示例参数：host", value = "主机.", dataType = "String", required = false),
			@ApiImplicitParam(name = "示例参数：result", value = "交易结果.", dataType = "String", required = false),
			@ApiImplicitParam(name = "示例参数：transactionName", value = "交易名称.", dataType = "String", required = false),
			@ApiImplicitParam(name = "示例参数：transactionType", value = "交易类型.", dataType = "String", required = false),
			@ApiImplicitParam(name = "示例参数：serviceName", value = "应用名称/服务名称.", dataType = "String", required = false),
	})
	@PostMapping("trace/listById")
	public R traceListById(@RequestBody NameBean param) {
		return biz.traceListById(param);
	}

	@ApiOperation(value = "服务拓补图", notes = "服务拓补图.")
	@ApiImplicitParams({
			@ApiImplicitParam(name = "param", value = "JSON对象.", paramType = "body", dataType = "Map", required = true),
			@ApiImplicitParam(name = "示例参数：start", value = "开始时间.", dataType = "String", required = false),
			@ApiImplicitParam(name = "示例参数：end", value = "结束时间.", dataType = "String", required = false),
			@ApiImplicitParam(name = "示例参数：environment", value = "环境.", dataType = "String", required = false),
			@ApiImplicitParam(name = "示例参数：serviceName", value = "应用名称/服务名称.", dataType = "String", required = false),
			@ApiImplicitParam(name = "示例参数：transactionResult", value = "交易结果.", dataType = "String", required = false),
	})
	@PostMapping("service/map")
	public R serviceMap(@RequestBody NameBean param) {
		return biz.serviceMap(param);
	}

	@ApiOperation(value = "拓补图详情", notes = "拓补图详情.")
	@ApiImplicitParams({
			@ApiImplicitParam(name = "param", value = "JSON对象.", paramType = "body", dataType = "Map", required = true),
			@ApiImplicitParam(name = "示例参数：start", value = "开始时间.", dataType = "String", required = false),
			@ApiImplicitParam(name = "示例参数：end", value = "结束时间.", dataType = "String", required = false),
			@ApiImplicitParam(name = "示例参数：environment", value = "环境.", dataType = "String", required = false),
			@ApiImplicitParam(name = "示例参数：serviceName", value = "应用名称/服务名称.", dataType = "String", required = false),
	})
	@PostMapping("service/mapDetail")
	public R serviceMapDetail(@RequestBody NameBean param) {
		return biz.mapDetail(param);
	}

	@ApiOperation(value = "接口列表", notes = "接口列表.")
	@ApiImplicitParams({
			@ApiImplicitParam(name = "param", value = "JSON对象.", paramType = "body", dataType = "Map", required = true),
			@ApiImplicitParam(name = "示例参数：start", value = "示例参数: 开始时间.", dataType = "String", required = false),
			@ApiImplicitParam(name = "示例参数：end", value = "示例参数: 结束时间.", dataType = "String", required = false),
			@ApiImplicitParam(name = "示例参数：environment", value = "示例参数: 环境.", dataType = "String", required = false),
			@ApiImplicitParam(name = "示例参数：serviceName", value = "示例参数: 应用名称/服务名称.", dataType = "String", required = false),
			@ApiImplicitParam(name = "示例参数：result", value = "交易结果.", dataType = "String", required = false),
			@ApiImplicitParam(name = "示例参数：traceId", value = "链路ID.", dataType = "String", required = false),
			@ApiImplicitParam(name = "示例参数：urlPath", value = "端点名称.", dataType = "String", required = false),
			@ApiImplicitParam(name = "示例参数：size", value = "页容.", dataType = "Integer", required = false),
	})
	@PostMapping("trace/search")
	public R search(@RequestBody NameBean param) {
		return biz.search(param);
	}

	@ApiOperation(value = "接口列表详情", notes = "接口列表详情.")
	@ApiImplicitParams({
			@ApiImplicitParam(name = "param", value = "JSON对象.", paramType = "body", dataType = "Map", required = true),
			@ApiImplicitParam(name = "示例参数：start", value = "示例参数: 开始时间.", dataType = "String", required = false),
			@ApiImplicitParam(name = "示例参数：end", value = "示例参数: 结束时间.", dataType = "String", required = false),
			@ApiImplicitParam(name = "示例参数：traceId", value = "链路ID.", dataType = "String", required = false),
	})
	@PostMapping("trace/searchById")
	public R searchById(@RequestBody NameBean param) {
		return biz.searchById(param);
	}

}